#ifndef OUTPUTFUNCTION_H
#define OUTPUTFUNCTION_H

#include <QObject>
#include "output.h"

class OutputFunction;
typedef struct __send_func
{
    const char *signal;
    const char* name;

}SendFun;

class OutputFunction : public QObject
{
    Q_OBJECT
public:



//    enum FunctionIndex
//    {
//        DISABLE = 0,

//        HIGH =1,
//        OK,
//        LOW,
//        BEEP,
//                TRAFFIC_IN,
//                TRAFFIC_OUT,
//                POINT,
//                RANGE,
//                STABLE,
//                NETGROSS,
//        START,
//    };
    enum {
        NONE = 0,
        START,HI,OK,LO,BEEP,PICKOUT,NG,R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14
    };
    enum {
        NORMALCLOSE = 0,NORMALOPEN
    };

    enum TrafficStatus
    {   
        TRAFFIC_UNDEFINED = -1,
        TRAFFIC_NO_WEIGHT = 0,//GREEN,RED

        TRAFFIC_WEIGHT_READY, //RED,  RED,
        TRAFFIC_WEIGHT_OK   //RED,  GREEN
        
    };
    static const QString OUTPUT_SET;
    static const QString OPERATION;
    static const QString NORMALSTATUS;
    static const QString HI_SET;
    static const QString LO_SET;
    static const QString POINT_SET;
    static const QString DELAYTIME;
    static const QString CONTINUETIME;
    static OutputFunction * getOutputFunctionMgr();
    QStringList operationNameList();
    QStringList normalStatusList();
    Output* getOutput(uint no) {return mOutputList.at(no);}
    QList<Output*> getOutputList() {return mOutputList;}
    float getOutputPoint(uint i);

    int outputIoCount();
    int OperationCount();

    int getNormalStatus(uint num);
    int getFunctionNum(uint num);
    int getStartDlyTime(uint num);
    int getContinueTime(uint num);

    QString getOutputSetting(uint i);
    QString getOperationName(uint i);
    Output::Range getOutputRange(uint i);

    void setStatus(uint num,Output::Status status);
    Output::Status getStatus(uint num);


    void saveOutputRange(uint i,Output::Range range);
    void saveOutputPoint(uint i,float f);
    void saveOutputFunction(uint num,uint normalStatus,uint functionNum,uint startDly,uint continueTime);

    bool haveFunction(uint num);
    QByteArray haveFunctionList(uint num);
    void checkWeight(float w);

public:


    void setTrafficStatus(TrafficStatus status);


    void setPointStatus(Output::Status status);
    void setRangeStatus(int index, Output::Status status);
    void setStableStatus(Output::Status status);
    void setTareStatus(Output::Status status);

    void setCheckHighStatus(Output::Status status);
    void setCheckOKStatus(Output::Status status);
    void setCheckLowStatus(Output::Status status);
    void setCheckBeepStatus(Output::Status status);
    void setStartStatus(Output::Status status);

    void setWeightOkStatus(Output::Status status);
//    void setPickOutStatus(Output::Status status);
    void setCheckNgStatus(Output::Status status);
signals:
    void s_trafficIn(Output::Status status);
    void s_trafficOut(Output::Status status);
    void s_point(Output::Status status);
    void s_range(Output::Status status);
    void s_stable(Output::Status status);
    void s_haveTare(Output::Status status);

    void s_High(Output::Status status);
    void s_OK(Output::Status status);
    void s_Low(Output::Status status);
//    void s_Beep(Output::Status status);
    void s_Beep(Output::Status);
    void s_Start(Output::Status);
    void s_Weight(Output::Status);
    void s_PickOut(Output::Status);
    void s_Ng(Output::Status);
    void s_R1(Output::Status);
    void s_R2(Output::Status);
    void s_R3(Output::Status);
    void s_R4(Output::Status);
    void s_R5(Output::Status);
    void s_R6(Output::Status);
    void s_R7(Output::Status);
    void s_R8(Output::Status);
    void s_R9(Output::Status);
    void s_R10(Output::Status);
    void s_R11(Output::Status);
    void s_R12(Output::Status);
    void s_R13(Output::Status);
    void s_R14(Output::Status);
    void s_R15(Output::Status);

    void getRangeResult(Output::Range);

private:
    static OutputFunction *mInstance;

    explicit OutputFunction(QObject *parent = 0);
    QList<Output *> mOutputList;

    static const char* NORMAL_STATUS[];

    static const SendFun mFunctionList[];
    static const int mOutputNoTab[];
    static const int mOutputTab_40[];


    TrafficStatus mStatus;
    int mOptMode;
public:
    void initOutputFunction(Output *io,  uint functionNum,bool normalStatus, uint startDly, uint continueTime);
};

#endif // OUTPUTFUNCTION_H
